package javawork;
import java.util.Scanner;

public class section9_11 {
    // 私有数据字段：方程系数a, b, c, d, e, f
    private double a, b, c, d, e, f;

    // 构造方法：初始化系数
    public section9_11(double a, double b, double c, double d, double e, double f) {
        this.a = a;
        this.b = b;
        this.c = c;
        this.d = d;
        this.e = e;
        this.f = f;
    }

    // 访问器方法
    public double getA() {
        return a;
    }

    public double getB() {
        return b;
    }

    public double getC() {
        return c;
    }

    public double getD() {
        return d;
    }

    public double getE() {
        return e;
    }

    public double getF() {
        return f;
    }

    // 判断方程是否可解（ad - bc != 0）
    public boolean isSolvable() {
        return (a * d - b * c) != 0;
    }

    // 计算x的解
    public double getX() {
        double denominator = a * d - b * c;
        return (e * d - b * f) / denominator;
    }

    // 计算y的解
    public double getY() {
        double denominator = a * d - b * c;
        return (a * f - e * c) / denominator;
    }

    // 测试程序
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        // 提示用户输入系数a, b, c, d, e, f
        System.out.print("Enter a, b, c, d, e, f: ");
        double a = input.nextDouble();
        double b = input.nextDouble();
        double c = input.nextDouble();
        double d = input.nextDouble();
        double e = input.nextDouble();
        double f = input.nextDouble();

        // 创建LinearEquation对象
        section9_11 equation = new section9_11(a, b, c, d, e, f);

        // 根据是否可解输出结果
        if (equation.isSolvable()) {
            double x = equation.getX();
            double y = equation.getY();
            System.out.println("x = " + x);
            System.out.println("y = " + y);
        } else {
            System.out.println("The equation has no solution.");
        }

        input.close();
    }
}